package com.wodan.zhongjinjicang.enums;

/**
 * 
 * @ClassName: ResponseCodeEnum 
 * @Description: 状态码枚举
 * @author Administrator
 * @date 2016-7-22 下午4:56:52 
 * @history 
 *
 */
public enum ResponseCodeEnum {
	SUCCESS(1,"成功"),
	FAIL(-1,"失败");

	private Integer code;
	private String desc;
	
	private ResponseCodeEnum(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	
	/**
	 * 转换
	 * */
	public  static String strNormaL(Integer value){
		for(ResponseCodeEnum type :values()){
			if (type.code == value){
				return type.getDesc();
			}
		}	
		return "";
	}
	/**
	 * 判断值是否合法
	 * @Description:
	 * @param code
	 * @return
	 */
	public static boolean isValid(Integer code) {
		for (ResponseCodeEnum type : values()) {
			if (type.code == code) {
				return true;
			}
		}
		
		return false;
	}

	/**
	 * valueOf
	 * 
	 * @Description:
	 * @param code
	 * @return
	 */
	public static ResponseCodeEnum valueOf(Integer code) {
		for (ResponseCodeEnum type : values()) {
			if (type.code == code) {
				return type;
			}
		}
		
		throw new IllegalArgumentException("unknown code, code=" + code);
	}
	
}
